from typing import List

nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]


def max_sum(nums: List[int]) -> int:
    if not nums:
        return 0
    cur_max = nums[0]
    glo_max = nums[0]

    for i in range(1, len(nums)):
        cur_max = max(cur_max + nums[i], nums[i])
        glo_max = max(glo_max, cur_max)

    return glo_max


print(max_sum(nums))
